package com.prs.crm.action.crm;

import java.io.File;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;


import com.prs.crm.annotation.Clew;
import com.prs.crm.domain.crm.Dispatch;
import com.prs.crm.domain.crm.DispatchBook;
import com.prs.crm.domain.crm.DispatchPerson;
import com.prs.crm.domain.crm.Recodhaifen;
import com.prs.crm.domain.crm.SerCurrentDate;
import com.prs.crm.domain.crm.mainBill;
import com.prs.crm.domain.sys.Code;
import com.prs.crm.domain.sys.CodeInvoice;
import com.prs.crm.service.crm.DispatchBookService;
import com.prs.crm.service.crm.DispatchPersonService;
import com.prs.crm.service.crm.DispatchService;
import com.prs.crm.service.crm.RecodhaifenService;
import com.prs.crm.service.crm.SerCurrentDateService;
import com.prs.crm.service.sys.CodeInvoiceService;
import com.prs.crm.service.sys.CodeService;

@SuppressWarnings("unchecked")
public class DispatchAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	private Code code;
	private CodeService codeService;
	private String Encode;
	private CodeInvoice codeInvoice;
	private CodeInvoiceService codeInvoiceService;
	private Collection<CodeInvoice> codelist;
	private Dispatch dispatch;
	private DispatchService dispatchService;
	private SerCurrentDateService serCurrentDateService;
	private DispatchPerson dispatchPerson;
	private DispatchPersonService dispatchPersonService;
	private DispatchBook dispatchBook;
	private DispatchBookService dispatchBookService;
	private Recodhaifen recodhaifen;
	private RecodhaifenService recodhaifenService;
	private String citys = "";
	private String judge;
	private String billNum;
	private String pagecord;
	private String judgepage = "1";
	/**
	 * 金额标识
	 */
	private String MaPay = "";
	/**
	 * 送货地点
	 */
	private String transportAddress = "";

	/**
	 * 货号
	 */
	private String[] codeNumber;
	/**
	 * 收货人姓名
	 */
	private String[] receiver;
	/**
	 * 联系电话
	 */
	private String[] phone;
	/**
	 * 品名
	 */
	private String[] productName;
	/**
	 * 数量
	 */
	private String[] Numbers;
	/**
	 * 代收款
	 */
	private Double[] collection;
	/**
	 * 提付
	 */
	private Double[] pay1;
	/**
	 * 已付
	 */
	private Double[] pay2;
	/**
	 * 回付
	 */
	private Double[] pay3;
	/**
	 * 收款人签名
	 */
	private String[] receiveName;
	/**
	 * 日期
	 */
	private String hidDtime;
	private String Dtime1;
	private Date Dtime;
	private int[] nums;
	private List numList = new LinkedList();
	private PaginationSupport pagination;
	private String[] ids;
	private String[] ids2;
	private File upload;
	private String uploadFileName;
	private Integer count;
	private String SerA = "";
	private String SerB;
	private String total_pay1;
	private String total_pay2;
	private String total_pay3;
	private String total;
	private String nextadressid = "0";
	// 修改的数据属性
	private String[] dishfRecods;
	private String[] agancyFunds_ys;
	private String[] transportCodes;
	private String[] receivePersons;
	private String[] telepones;
	private String[] productNames;
	private String[] productNums;
	private String[] agancyFunds;
	private String[] submitFunds;
	private String[] paidFunds;
	private String[] conterpartFunds;
	private String[] anotherPersons;

	private String pay1x;
	private String pay2x;
	private String pay3x;
	private String allpay;

	private String pay1_ys;
	private String pay2_ys;
	private String pay3_ys;
	private String allpay_ys;

	private String[] ttfVpay;
	private String[] yyfVpay;
	private String[] hhfVpay;
	private String[] pPeronss;
	// 最后一页新增属性
	private String[] addJuds;
	private String adddisCodes;
	private String[] addAdreess;
	private String[] addtransportCodes;
	private String[] addreceivePersons;
	private String[] addtelepones;
	private String[] addproductNames;
	private String[] addproductNums;
	private String[] addagancyFunds;
	private String[] addsubmitFunds;
	private String[] addpaidFunds;
	private String[] addconterpartFunds;
	private String[] addanotherPersons;

	private String allpay1;
	private String allpay2;
	private String allpay3;
	private String allpayAlls;

	@Action("editDispatch")
	public String editFeedback() {
		this.codelist = this.getCodeInvoiceService().getInvoiceCodeType("海风运输");
		hidDtime = NewTime();
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Dtime1 = df.format(new Date()) + "";
		for (int i = 0; i < 24; i++) {
			numList.add(i);
		}
		return SUCCESS;
	}

	@Action("addviewAllDispatch")
	public String addviewAllDispatch() {
		judge = (Integer.parseInt(judge) + 1) + "";
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String hidDtimex = df.format(new Date());
		String dates[] = hidDtimex.split("-");
		hidDtime = dates[0] + "年" + dates[1] + "月" + dates[2] + "日";
		Dtime1 = df.format(new Date()) + "";
		List<Dispatch> slistd = this.getDispatchService().getNumToDispatch(billNum);
		if (!slistd.isEmpty()) {
			dispatch = slistd.get(0);
		}
		for (int i = 0; i < 24; i++) {
			numList.add("");
		}

		return SUCCESS;
	}

	@Clew(results = { "success", "none", "error" })
	@Action(value = "saveDispatch", results = {
			@Result(name = "success", type = "redirect", location = "editDispatch"),
			@Result(name = "nextpage", type = "redirect", location = "editDispatch?judgepage=${judgepage}& MaPay=${MaPay}& SerA=${SerA}&SerB=${SerB}"),
			@Result(name = "error", type = "redirect", location = "editDispatch") })
	public String save() {
		int initaliV = 0;
		Double p1=0.0,p2=0.0,p3=0.0,pa=0.0;
		if (transportAddress == null || "".equals(transportAddress)) {
			this.addActionError("发货地址不能为空");
			return ERROR;
		} else {
			CandleNull();
			List<SerCurrentDate> serCurrentDates = new ArrayList<SerCurrentDate>();
			/**
			 * 如果judge!=null,是下一页
			 */

			if (judge != null) {
				/**
				 * 生成新页码
				 */
				judgepage = (Integer.parseInt(pagecord) + 1) + "";

				Recodhaifen ob_hf = this.getRecodhaifenService().getRecord();
				String regularR = "";
				if (ob_hf == null) {
					regularR = getRedNew();
				} else {
					regularR = ob_hf.getRecordNum();
				}
				if (pagecord == null) {
					judgepage = "1";
				} else {
					judgepage = (Integer.parseInt(pagecord) + 1) + "";
				}

				/**
				 * 判断是否有数据
				 */

				for (int i = 0; i < receiver.length; i++) {

					/**
					 * 判断是否建立帐溥
					 */
					if (receiver[i] == null || "".equals(receiver[i])) {

					} else {
						FilterNull(i);

						Dispatch ob_dp = new Dispatch();
						ob_dp.setTransportAddress(transportAddress);
						ob_dp.setTransportDate(Dtime);
						ob_dp.setTransportCode(codeNumber[i]);
						ob_dp.setReceivePerson(receiver[i]);
						ob_dp.setTelepone(phone[i]);
						ob_dp.setProductName(productName[i]);
						ob_dp.setProductNum(Integer.parseInt(Numbers[i]));
						ob_dp.setAgancyFund(collection[i]);
						ob_dp.setConterpartFund(pay3[i]);
						ob_dp.setSubmitFund(pay1[i]);
						ob_dp.setPaidFund(pay2[i]);
						ob_dp.setAllPay1("0");
						ob_dp.setAllPay2("0");
						ob_dp.setAllPay3("0");
						ob_dp.setAlltotalPay("0");
						ob_dp.setAnotherPerson(receiveName[i]);
						ob_dp.setDispageNum(pagecord);

						if (i == 0) {
							try {
								DateFormat sdf = new SimpleDateFormat(
										"yyyy-MM-dd");
								String d = sdf.format(Dtime);
								Date date = sdf.parse(d);

								serCurrentDates = this
										.getSerCurrentDateService().getByDate(
												date);
								SerCurrentDate serCurrentDate;

								List<Dispatch> slistd = this
										.getDispatchService().getNumToDispatch(
												dispatch.getDishfRecod());
								if (slistd.isEmpty()) {
									if (serCurrentDates.isEmpty()) {
										serCurrentDate = new SerCurrentDate();
										serCurrentDate
												.setSubmitFund(SysoutPay1(codeNumber.length));
										serCurrentDate
												.setPaidFund(SysoutPay2(codeNumber.length));
										serCurrentDate
												.setConterpartFund(SysoutPay3(codeNumber.length));
										serCurrentDate.setTotalFund(Double
												.parseDouble(ob_dp
														.getAlltotalPay()));
										serCurrentDate.setDateFund(date);
										this.getSerCurrentDateService().save(
												serCurrentDate);
									} else {
										serCurrentDate = serCurrentDates.get(0);
										serCurrentDate
												.setSubmitFund(Double
														.parseDouble(ob_dp
																.getAllPay1())
														+ serCurrentDate
																.getSubmitFund());
										serCurrentDate
												.setPaidFund(Double
														.parseDouble(ob_dp
																.getAllPay2())
														+ serCurrentDate
																.getPaidFund());
										serCurrentDate
												.setConterpartFund(Double
														.parseDouble(ob_dp
																.getAllPay3())
														+ serCurrentDate
																.getConterpartFund());
										serCurrentDate
												.setTotalFund(serCurrentDate
														.getConterpartFund()
														+ serCurrentDate
																.getSubmitFund()
														+ serCurrentDate
																.getPaidFund());
										this.getSerCurrentDateService().submit(
												serCurrentDate);
									}
								} else {

									Dispatch xh = slistd.get(slistd.size()-1);
									p1=SysoutPay1(codeNumber.length) + Double.parseDouble(xh.getAllPay1());
									p2=SysoutPay2(codeNumber.length) + Double.parseDouble(xh.getAllPay2());
									p3=SysoutPay3(codeNumber.length) + Double.parseDouble(xh.getAllPay3());
									pa=p1+p2+p3;
								    if (!serCurrentDates.isEmpty()) {
										serCurrentDate = serCurrentDates.get(0);
										serCurrentDate.setSubmitFund(SysoutPay1(codeNumber.length)
												+ serCurrentDate
														.getSubmitFund());
										serCurrentDate.setPaidFund(SysoutPay2(codeNumber.length)
												+ serCurrentDate.getPaidFund());
										serCurrentDate.setConterpartFund(SysoutPay3(codeNumber.length)
												+ serCurrentDate
														.getConterpartFund());
										serCurrentDate
												.setTotalFund(serCurrentDate
														.getConterpartFund()
														+ serCurrentDate
																.getSubmitFund()
														+ serCurrentDate
																.getPaidFund());
										this.getSerCurrentDateService().submit(
												serCurrentDate);
									}

								}
							} catch (ParseException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}

						}
						
						ob_dp.setAllPay1(p1+"");
						ob_dp.setAllPay2(p2+"");
						ob_dp.setAllPay3(p3+"");
						ob_dp.setAlltotalPay(pa+ "");
						ob_dp.setDnpay1(SysoutPay1(codeNumber.length) + "");
						ob_dp.setDnpay2(SysoutPay2(codeNumber.length) + "");
						ob_dp.setDnpay3(SysoutPay3(codeNumber.length) + "");
						ob_dp.setDnpayAll(SysoutPay1(codeNumber.length)
								+ SysoutPay2(codeNumber.length)
								+ SysoutPay3(codeNumber.length) + "");

						ob_dp.setDishfRecod(dispatch.getDishfRecod());
						this.getDispatchService().save(ob_dp);

						/**
						 * 查询是否在人员表里面是否存在此人
						 */
						int judgePerson = this.getDispatchPersonService()
								.SerchPerson(receiver[i].trim(),
										transportAddress.trim());
						if (judgePerson == 0) {
							DispatchPerson ob_de = new DispatchPerson();
							ob_de.setPeAdress(transportAddress);
							ob_de.setPeName(receiver[i]);
							ob_de.setPeTelepone(phone[i]);
							ob_de.setPerhfRecod(dispatch.getDishfRecod());
							this.getDispatchPersonService().save(ob_de);
						}
						if (collection[i] == null || collection[i] == 0) {
							/**
							 * 不建立
							 */
						} else {
							/**
							 * 建立
							 */

							DispatchBook ob_dpb = new DispatchBook();
							ob_dpb.setBoCode(codeNumber[i]);
							ob_dpb.setBoDate(Dtime);
							ob_dpb.setBoAdress(transportAddress);
							ob_dpb.setBoAmount(collection[i]);
							ob_dpb.setBoName(receiver[i]);
							ob_dpb.setBoohfRecod(dispatch.getDishfRecod());
							ob_dpb.setBopageNum(pagecord);
							ob_dpb.setDispatch(ob_dp);
							ob_dpb.setBoCDate("");
							ob_dpb.setBoQDate("");
							ob_dpb.setBoAcName("");
							this.getDispatchBookService().save(ob_dpb);
						}
					}
				}

				MaPay = SysoutPay1(codeNumber.length) + ","
						+ SysoutPay2(codeNumber.length) + ","
						+ SysoutPay3(codeNumber.length);
				SerA = dispatch.getDishfRecod();
				if(codeInvoice==null){
					SerB=dispatch.getDishfRecod();
				}else{
				    SerB = codeInvoice.getId() + "";
				}
				return "nextpage";
			}
			/**
			 * 上面是点击下一页进入
			 */
			else {

				/**
				 * 下面是确定提交
				 */

				Recodhaifen ob_hf = this.getRecodhaifenService().getRecord();
				String regularR = "";
				// System.out.println("对象是="+ob_hf);
				if (ob_hf == null) {
					regularR = getRedNew();
				} else {
					regularR = ob_hf.getRecordNum();
				}
				if (pagecord == null) {
					judgepage = "1";
				} else {
					judgepage = (Integer.parseInt(pagecord) + 1) + "";
				}
				for (int i = 0; i < codeNumber.length; i++) {
					/**
					 * 判断是否建立帐溥
					 */
					if (receiver[i] == null || "".equals(receiver[i])) {

					} else {
						FilterNull(i);
						Dispatch ob_dp = new Dispatch();
						ob_dp.setTransportAddress(transportAddress);
						ob_dp.setTransportDate(Dtime);
						ob_dp.setTransportCode(codeNumber[i]);
						ob_dp.setReceivePerson(receiver[i]);
						ob_dp.setTelepone(phone[i]);
						ob_dp.setProductName(productName[i]);
						ob_dp.setProductNum(Integer.parseInt(Numbers[i]));
						ob_dp.setAgancyFund(collection[i]);
						ob_dp.setSubmitFund(pay1[i]);
						ob_dp.setPaidFund(pay2[i]);
						ob_dp.setConterpartFund(pay3[i]);
						ob_dp.setAnotherPerson(receiveName[i]);
						ob_dp.setDispageNum(pagecord);
						
						if (i == 0) {
							try {
								DateFormat sdf = new SimpleDateFormat(
										"yyyy-MM-dd");
								String d = sdf.format(Dtime);
								Date date = sdf.parse(d);

								serCurrentDates = this
										.getSerCurrentDateService().getByDate(
												date);

								SerCurrentDate serCurrentDate;
								List<Dispatch> slistd = this.getDispatchService().getNumToDispatch(dispatch.getDishfRecod());	
								if (slistd.isEmpty()) {
									p1=SysoutPay1(codeNumber.length);
									p2=SysoutPay2(codeNumber.length);
									p3=SysoutPay3(codeNumber.length);
									pa=p1+p2+p3;

									if (serCurrentDates.isEmpty()) {
										serCurrentDate = new SerCurrentDate();
										serCurrentDate
												.setSubmitFund(SysoutPay1(codeNumber.length));
										serCurrentDate
												.setPaidFund(SysoutPay2(codeNumber.length));
										serCurrentDate
												.setConterpartFund(SysoutPay3(codeNumber.length));
										serCurrentDate.setTotalFund(serCurrentDate.getConterpartFund()+serCurrentDate.getPaidFund()+serCurrentDate.getSubmitFund());
										serCurrentDate.setDateFund(date);
										this.getSerCurrentDateService().save(
												serCurrentDate);
									} else {
										serCurrentDate = serCurrentDates.get(0);
										serCurrentDate
												.setSubmitFund(SysoutPay1(codeNumber.length)
														+ serCurrentDate
																.getSubmitFund());
										serCurrentDate
												.setPaidFund(SysoutPay2(codeNumber.length)
														+ serCurrentDate
																.getPaidFund());
										serCurrentDate
												.setConterpartFund(SysoutPay3(codeNumber.length)
														+ serCurrentDate
																.getConterpartFund());
										serCurrentDate
												.setTotalFund(serCurrentDate
														.getConterpartFund()
														+ serCurrentDate
																.getSubmitFund()
														+ serCurrentDate
																.getPaidFund());
										this.getSerCurrentDateService().submit(
												serCurrentDate);
									}
								} else {
									Dispatch xh = slistd.get(slistd.size()-1);
									MaPay=null;
									p1=SysoutPay1(codeNumber.length) + Double.parseDouble(xh.getAllPay1());
									p2=SysoutPay2(codeNumber.length) + Double.parseDouble(xh.getAllPay2());
									p3=SysoutPay3(codeNumber.length) + Double.parseDouble(xh.getAllPay3());
									pa=p1+p2+p3;
																
									if (!serCurrentDates.isEmpty()) {
										serCurrentDate = serCurrentDates.get(0);
										serCurrentDate.setSubmitFund(SysoutPay1(codeNumber.length)
												+ serCurrentDate
														.getSubmitFund());
										serCurrentDate.setPaidFund(SysoutPay2(codeNumber.length)
												+ serCurrentDate.getPaidFund());
										serCurrentDate.setConterpartFund(SysoutPay2(codeNumber.length)
												+ serCurrentDate
														.getConterpartFund());
										serCurrentDate
												.setTotalFund(serCurrentDate
														.getConterpartFund()
														+ serCurrentDate
																.getSubmitFund()
														+ serCurrentDate
																.getPaidFund());
										this.getSerCurrentDateService().submit(
												serCurrentDate);
									}
								}

							} catch (ParseException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
						}
						ob_dp.setAllPay1(p1+"");
						ob_dp.setAllPay2(p2+"");
						ob_dp.setAllPay3(p3+"");
						ob_dp.setAlltotalPay(pa
								+ "");

						// System.out.println("保存输出1："+(SysoutPay1(codeNumber.length)
						// + "")+"="+i);
						ob_dp.setDnpay1(SysoutPay1(codeNumber.length) + "");
						// System.out.println("保存输出2："+(SysoutPay2(codeNumber.length)
						// + "")+"="+i);
						ob_dp.setDnpay2(SysoutPay2(codeNumber.length) + "");
						// System.out.println("保存输出3："+(SysoutPay3(codeNumber.length)
						// + "")+"="+i);
						ob_dp.setDnpay3(SysoutPay3(codeNumber.length) + "");

						ob_dp.setDnpayAll((SysoutPay1(codeNumber.length)
								+ SysoutPay2(codeNumber.length) + SysoutPay3(codeNumber.length))
								+ "");

						ob_dp.setDishfRecod(dispatch.getDishfRecod());

						this.getDispatchService().save(ob_dp);
						// System.out.println("zhix:"+ob_dp);
						/**
						 * 查询是否在人员表里面是否存在此人
						 */
						int judgePerson = this.getDispatchPersonService()
								.SerchPerson(receiver[i].trim(),
										transportAddress.trim());
						if (judgePerson == 0) {
							DispatchPerson ob_de = new DispatchPerson();
							ob_de.setPeAdress(transportAddress);
							ob_de.setPeName(receiver[i]);
							ob_de.setPeTelepone(phone[i]);
							ob_de.setPerhfRecod(dispatch.getDishfRecod());
							this.getDispatchPersonService().save(ob_de);
						}

						if (collection[i] == null || collection[i] == 0) {
							/**
							 * 不建立
							 */
						} else {
							/**
							 * 建立
							 */

							DispatchBook ob_dpb = new DispatchBook();
							ob_dpb.setBoCode(codeNumber[i]);
							ob_dpb.setBoDate(Dtime);
							ob_dpb.setBoAmount(collection[i]);
							ob_dpb.setBoAdress(transportAddress);
							ob_dpb.setBoName(receiver[i]);
							ob_dpb.setBoohfRecod(dispatch.getDishfRecod());
							ob_dpb.setBopageNum(pagecord);
							ob_dpb.setDispatch(ob_dp);
							ob_dpb.setBoCDate("");
							ob_dpb.setBoQDate("");
							ob_dpb.setBoAcName("");
							this.getDispatchBookService().save(ob_dpb);
						}

					}

				}

				/**
				 * 主编号
				 */
				int mb = this.getRecodhaifenService().SerchBill(
						dispatch.getDishfRecod());
				if (mb == 0) {
					mainBill ob_mb = new mainBill();
					DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
					String Dtime1 = df.format(Dtime);
					ob_mb.setCurrentTime(Dtime1);
					ob_mb.setBillNum(dispatch.getDishfRecod());

					if (initaliV == 0) {
						if ("n".equals(Encode)) {

						} else {
							CodeInvoice Vob = this.getCodeInvoiceService()
									.getVobject(codeInvoice.getId());
							Code codes = new Code();
							codes.setEntityName(ob_mb.getClass().getName());
							codes.setCodeValue(dispatch.getDishfRecod());
							Vob.setNumBackUp(Increase(Vob.getNumBackUp()));
							this.getCodeInvoiceService().saveOrUpdate(Vob);
							codes.setCodeType(Vob.getCodePlan());
							codes.setCodeMolde("海风运输");
							this.getCodeService().save(codes);
							ob_mb.setCode(codes);
						}

						initaliV++;
					}

					this.getRecodhaifenService().saveBill(ob_mb);

				}
				Recodhaifen ob_hf1 = this.getRecodhaifenService().getRecord();
				// System.out.println("ob_hf="+ob_hf1);
				AddRe(ob_hf1);

				this.setPrompt("发货单建立成功");

				return SUCCESS;

			}
		}

	}

	@Action("listDispatch")
	public String listDispatch() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				Dispatch.class);

		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getDispatchService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}

	@Action("listSerCurrentDate")
	public String listSerCurrentDate() {
		countData();
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				SerCurrentDate.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getSerCurrentDateService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}

	@Action("listMainbill")
	public String listMainbill() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				mainBill.class);

		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getDispatchService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}

	@Action("listDispatchBook")
	public String listDispatchBook() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				DispatchBook.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getDispatchService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}

	@Action("listDispatchPerson")
	public String listDispatchPerson() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				DispatchPerson.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getDispatchService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}

	@Action("viewDispatch")
	public String viewFeedback() {
		dispatch = this.getDispatchService().get(dispatch.getId());
		String hjdate[] = MessageFormat.format("{0,date,yyyy-MM-dd HH:mm:ss}",
				dispatch.getRecordTime()).split("-");
		hidDtime = hjdate[0] + "年" + hjdate[1] + "月" + hjdate[2] + "日";

		return SUCCESS;
	}

	@Action("viewDispatchBook")
	public String viewDispatchBook() {
		dispatchBook = this.getDispatchBookService().get(dispatchBook.getId());
		return SUCCESS;
	}

	public static boolean isNumeric(String str) {
		for (int i = str.length(); --i >= 0;) {
			if (!Character.isDigit(str.charAt(i))) {
				return false;
			}
		}
		return true;
	}

	/**
	 * 修改数据
	 * 
	 * @return
	 */
	@Clew(results = { "success", "none", "error" })
	@Action(value = "saveModifyData", results = {
			@Result(name = "success", type = "redirect", location = "listCurentTime"),
			@Result(name = "error", type = "redirect", location = "listCurentTime") })
	public String saveModifyData() {

		// 修改数据ID值是每行必有得。
		// 当前修改页的长度
		int timeSize = ids.length;
		// 当前页有24条数据的
		if (timeSize == 24) {
			int substuteV = 0;
			for (int i = 0; i < timeSize; i++) {
				// 删除该列的也有的数据
				if (setTF(transportCodes[i]) && setTF(receivePersons[i])
						&& setTF(telepones[i]) && setTF(productNames[i])
						&& setTF(productNums[i]) && setTF(agancyFunds[i])
						&& setTF(submitFunds[i]) && setTF(paidFunds[i])
						&& setTF(conterpartFunds[i])
						&& setTF(anotherPersons[i])) {
					// 数据删除----------------
					// System.out.println("删除数据--ID:"+ids[i]);
					Dispatch dsOnject = this.getDispatchService().get(
							Integer.parseInt(ids[i]));
					// 判断该列账簿里面是否有数据
					if (setTF(agancyFunds_ys[i]) == false) {
						// 有数据
						DispatchBook dsBookObject = this
								.getDispatchBookService().getDispatchBook(
										dsOnject);
						if (dsBookObject == null) {
						} else {
							this.getDispatchBookService().remove(dsBookObject);
						}
					}

					// 人员替补操作
					List<Dispatch> dpList = this.getDispatchService()
							.getByNameandByAdress(pPeronss[i],
									dsOnject.getTransportAddress());
					if (dpList.size() == 0) {
						DispatchPerson pNum = this.getDispatchPersonService()
								.getDispatchPerson(pPeronss[i],
										dsOnject.getTransportAddress());
						if (pNum == null) {
						} else {
							this.getDispatchPersonService().remove(pNum);
						}
					}

					// 删除数据库里面的数据
					this.getDispatchService().remove(dsOnject);

					// 数据替补操作
					List<Dispatch> alldisList = this.getDispatchService()
							.getNumToDispatch(dishfRecods[i]);

					int jSize = alldisList.size();
					// 计算总共有几页
					int pageAl = setDsPage(jSize);
					// 当前处理的页码。
					String currentPage = pagecord;
					if (jSize > 24) {
						String currentPages = "";
						double submitFund = 0.0;
						double paidFund = 0.0;
						double conterpartFund = 0.0;
						double allpays = 0.0;
						int zj = 1;
						while (currentPage.equals(alldisList.get(jSize - zj)
								.getDispageNum())) {
							zj++;
						}

						Dispatch currentdisObx = alldisList.get(jSize - zj);
						// 把最后一条数据填充到删除的那条数据
						currentdisObx.setDispageNum(currentPage);
						currentPages = currentdisObx.getDispageNum();
						submitFund = setFils(currentdisObx.getSubmitFund() + "");
						paidFund = setFils(currentdisObx.getPaidFund() + "");
						conterpartFund = setFils(currentdisObx
								.getConterpartFund() + "");

						this.getDispatchService().submit(currentdisObx);
						// 判断最后一页剩余的数据条数
						List<Dispatch> lastList = this.getDispatchService()
								.getNumpageToDispatch(dishfRecods[i],
										currentPages);
						if (lastList.size() > 0) {
							// 还有剩余页
							for (Dispatch dp : lastList) {
								// 当页数据变更
								dp.setDnpay1((setFils(dp.getDnpay1()) - submitFund)
										+ "");
								dp.setDnpay2((setFils(dp.getDnpay2()) - paidFund)
										+ "");
								dp.setDnpay3((setFils(dp.getDnpay3()) - conterpartFund)
										+ "");
								dp.setDnpayAll((setFils(dp.getDnpayAll()) - (submitFund
										+ paidFund + conterpartFund))
										+ "");
								// 所有数据变更

								// System.out.println("dp.getAllPay1():"+setFils(dp.getAllPay1()));

								// dp.setAllPay1((setFils(dp.getAllPay1()) -
								// submitFund)
								// + "");
								// dp.setAllPay2((setFils(dp.getAllPay2()) -
								// paidFund)
								// + "");
								// dp.setAllPay3((setFils(dp.getAllPay3()) -
								// conterpartFund)
								// + "");
								// dp.setAlltotalPay((setFils(dp.getAlltotalPay())
								// - (submitFund
								// + paidFund + conterpartFund))
								// + "");
								this.getDispatchService().submit(dp);
							}
							// 统计数据变更----------------------------------------------------
							setCount(dishfRecods[i]);
						} else {
							// 没有剩余页
							List<Dispatch> lastListd = this
									.getDispatchService().getNumToDispatch(
											dishfRecods[i]);
							if (lastListd.size() <= 24) {
								double ch1 = 0.0;
								double ch2 = 0.0;
								double ch3 = 0.0;
								double chAll = 0.0;
								for (Dispatch ch : lastListd) {
									ch1 = ch1 + ch.getSubmitFund();
									ch2 = ch2 + ch.getPaidFund();
									ch3 = ch3 + ch.getConterpartFund();

								}
								chAll = ch3 + ch2 + ch1;
								List<Dispatch> jkLisy = this
										.getDispatchService()
										.getNumpageToDispatch(
												dishfRecods[i],
												setDsPage(lastListd.size())
														+ "");
								double ch11 = 0.0;
								double ch21 = 0.0;
								double ch31 = 0.0;
								double chAll1 = 0.0;
								for (Dispatch oo : jkLisy) {
									ch11 = ch11 + oo.getSubmitFund();
									ch21 = ch21 + oo.getPaidFund();
									ch31 = ch31 + oo.getConterpartFund();
								}
								chAll1 = ch31 + ch21 + ch11;
								for (Dispatch hj : jkLisy) {
									hj.setDnpay1(ch11 + "");
									hj.setDnpay2(ch21 + "");
									hj.setDnpay3(ch31 + "");
									hj.setDnpayAll(chAll1 + "");
									hj.setAllPay1(ch1 + "");
									hj.setAllPay2(ch2 + "");
									hj.setAllPay3(ch3 + "");
									hj.setAlltotalPay(chAll + "");
									this.getDispatchService().submit(hj);
								}
								// 统计数据变更-----------------------------------------------
								setCount(dishfRecods[i]);
							}
						}
						// 价格数据调整
						List<Dispatch> disfList = this.getDispatchService()
								.getNumpageToDispatch(dishfRecods[i],
										currentPage);
						double tfV = setFils(ttfVpay[i]) - submitFund;
						double yfV = setFils(yyfVpay[i]) - paidFund;
						double hfV = setFils(hhfVpay[i]) - conterpartFund;
						double allV = tfV + yfV + hfV;
						for (Dispatch dos : disfList) {
							dos.setDnpay1((setFils(dos.getDnpay1()) - tfV) + "");
							dos.setDnpay2((setFils(dos.getDnpay2()) - yfV) + "");
							dos.setDnpay3((setFils(dos.getDnpay3()) - hfV) + "");
							dos.setDnpayAll((setFils(dos.getDnpayAll()) - allV)
									+ "");
							this.getDispatchService().submit(dos);
						}

					} else if (jSize == 24) {

						String currentPages = "";
						double submitFund = 0.0;
						double paidFund = 0.0;
						double conterpartFund = 0.0;
						double allpays = 0.0;
						int zj = 1;
						while (currentPage.equals(alldisList.get(jSize - zj)
								.getDispageNum())) {
							zj++;
						}
						Dispatch currentdisOb = alldisList.get(jSize - zj);
						// 把最后一条数据填充到删除的那条数据
						currentdisOb.setDispageNum(currentPage);
						currentPages = currentdisOb.getDispageNum();
						submitFund = setFils(currentdisOb.getSubmitFund() + "");
						paidFund = setFils(currentdisOb.getPaidFund() + "");
						conterpartFund = setFils(currentdisOb
								.getConterpartFund() + "");

						this.getDispatchService().submit(currentdisOb);

						List<Dispatch> lastList = this.getDispatchService()
								.getNumpageToDispatch(dishfRecods[i],
										currentPages);
						if (lastList.size() > 0) {
							for (Dispatch dp : lastList) {
								// 当页数据变更
								dp.setDnpay1((setFils(dp.getDnpay1()) - submitFund)
										+ "");
								dp.setDnpay2((setFils(dp.getDnpay2()) - paidFund)
										+ "");
								dp.setDnpay3((setFils(dp.getDnpay3()) - conterpartFund)
										+ "");
								dp.setDnpayAll((setFils(dp.getDnpayAll()) - (submitFund
										+ paidFund + conterpartFund))
										+ "");
								// // 所有数据变更
								// dp.setAllPay1((setFils(dp.getAllPay1()) -
								// submitFund)
								// + "");
								// dp.setAllPay2((setFils(dp.getAllPay2()) -
								// paidFund)
								// + "");
								// dp.setAllPay3((setFils(dp.getAllPay3()) -
								// conterpartFund)
								// + "");
								// dp.setAlltotalPay((setFils(dp.getAlltotalPay())
								// - (submitFund
								// + paidFund + conterpartFund))
								// + "");
								this.getDispatchService().submit(dp);
							}
							// 统计数据变更-----------------------------------------------
							setCount(dishfRecods[i]);
						}

					} else if (jSize < 24) {
						double tfV = setFils(ttfVpay[i]);
						double yfV = setFils(yyfVpay[i]);
						double hfV = setFils(hhfVpay[i]);
						double allV = tfV + yfV + hfV;
						List<Dispatch> lastList = this.getDispatchService()
								.getNumpageToDispatch(dishfRecods[i],
										currentPage);
						if (lastList.size() > 0) {
							for (Dispatch dp : lastList) {
								// 当页数据变更
								dp.setDnpay1((setFils(dp.getDnpay1()) - tfV)
										+ "");
								dp.setDnpay2((setFils(dp.getDnpay2()) - yfV)
										+ "");
								dp.setDnpay3((setFils(dp.getDnpay3()) - hfV)
										+ "");
								dp.setDnpayAll((setFils(dp.getDnpayAll()) - allV)
										+ "");
								// // 所有数据变更
								// dp.setAllPay1((setFils(dp.getAllPay1()) -
								// tfV)
								// + "");
								// dp.setAllPay2((setFils(dp.getAllPay2()) -
								// yfV)
								// + "");
								// dp.setAllPay3((setFils(dp.getAllPay3()) -
								// hfV)
								// + "");
								// dp.setAlltotalPay((setFils(dp.getAlltotalPay())
								// - allV)
								// + "");
								this.getDispatchService().submit(dp);
							}
							// 统计数据变更-----------------------------------------------
							setCount(dishfRecods[i]);
						}
					}

				} else {
					// 数据的更改
					// System.out.println("数据修改");----------------------------------------------------------
					double tfV = 0.0;
					double yfV = 0.0;
					double hfV = 0.0;
					Dispatch dsObject = this.getDispatchService().get(
							Integer.parseInt(ids[i]));
					dsObject.setTransportCode(transportCodes[i]);
					
					// 人员操作
//					System.out.println("人员操作 ："+"receivePersons[i]="+receivePersons[i]+"     dsObject.getReceivePerson()="+dsObject.getReceivePerson());	
					if (!(receivePersons[i].trim()).equals(dsObject
							.getReceivePerson().trim())) {
					    DispatchBook bookO=this.getDispatchBookService().getDispatchBook(dsObject);
					    if(bookO!=null){
					    	bookO.setBoName(receivePersons[i]);
					    	this.getDispatchBookService().submit(bookO);
					    }
						DispatchPerson dt = this.getDispatchPersonService().getDispatchPerson(receivePersons[i],dsObject.getTransportAddress());
						
						if (dt == null) {
							DispatchPerson dpp = new DispatchPerson();
							dpp.setPeAdress(dsObject.getTransportAddress());
							dpp.setPeName(receivePersons[i]);
							if ("".equals(telepones[i]) || telepones[i] == null) {
								dpp.setPeTelepone("");
							} else {
								dpp.setPeTelepone(telepones[i]);
							}
							dpp.setPerhfRecod(dsObject.getDishfRecod());
							this.getDispatchPersonService().save(dpp);

						}

						// 原有人员操作
						// Dispatch
						// dsp=this.getDispatchService().getByNameandByAdress(dsObject.get,
						// adress)
					}
					dsObject.setReceivePerson(receivePersons[i]);
					dsObject.setTelepone(setFiles(telepones[i]));
					dsObject.setProductName(setFiles(productNames[i]));
					dsObject.setProductNum(Integer.parseInt(productNums[i]));
					
					if (setFils(agancyFunds[i].trim())!=dsObject.getAgancyFund()) {
					
						if ("".equals(agancyFunds[i]) || agancyFunds[i] == null) {
							
							DispatchBook dpBObject = this
									.getDispatchBookService().getDispatchBook(
											this.getDispatchService().get(
													Integer.parseInt(ids[i])));
							if (dpBObject != null) {
								this.getDispatchBookService().remove(dpBObject);
							}
						} else {

							DispatchBook dpBObject = this.getDispatchBookService().getDispatchBook(this.getDispatchService().get(Integer.parseInt(ids[i])));
							if (dpBObject != null) {
								dpBObject.setBoName(receivePersons[i]);
								dpBObject.setBoAmount(setFils(agancyFunds[i]));
								this.getDispatchBookService().submit(dpBObject);
							} else {
								if (dsObject.getAgancyFund()==0
										|| dsObject.getAgancyFund() == null) {
									DispatchBook ajObject = new DispatchBook();
									ajObject.setBoAdress(dsObject
											.getTransportAddress());
									ajObject.setBoAmount(setFils(agancyFunds[i]));
									ajObject.setBoName(receivePersons[i]);
									ajObject.setBoohfRecod(dishfRecods[i]);
									ajObject.setBoDate(new Date());
									ajObject.setBopageNum(pagecord);
									ajObject.setDispatch(dsObject);
									ajObject.setBoCode(setFiles(transportCodes[i]));
									ajObject.setBoCDate("");
									ajObject.setBoQDate("");
									ajObject.setBoAcName("");
									this.getDispatchBookService()
											.save(ajObject);
								}
							}
						}
//						if (dsObject.getAgancyFund()==0
//								|| dsObject.getAgancyFund() == null) {
//							DispatchBook dsBok = new DispatchBook();
//							dsBok.setBoAdress(dsObject.getTransportAddress());
//							dsBok.setBoAmount(Double
//									.parseDouble(productNums[i]));
//							dsBok.setBoCode(transportCodes[i]);
//							dsBok.setBoName(receivePersons[i]);
//							dsBok.setBoohfRecod(dsObject.getDishfRecod());
//							dsBok.setBopageNum(pagecord);
//							dsBok.setDispatch(this.getDispatchService().get(
//									Integer.parseInt(ids[i])));
//							this.getDispatchBookService().save(dsBok);
//						}
					}

					// 是否更改总值的判断值
					int jud = 0;
					double tfdoub = 0.0;
					double tfdoub1 = 0.0;
					double tfdoub2 = 0.0;
					// tf
					if (!submitFunds[i].equals(dsObject.getSubmitFund())) {
						// System.out.println("tf:"+submitFunds[i]+"----"+dsObject.getSubmitFund());
						tfdoub = -(setFils(dsObject.getSubmitFund() + "") - setFils(submitFunds[i]));
						// System.out.println("tf结果："+tfdoub);
						if (tfdoub > 0) {
							dsObject.setDnpay1((setFils(dsObject.getDnpay1()) - tfdoub)
									+ "");
						}
						if (tfdoub < 0) {
							dsObject.setDnpay1((setFils(dsObject.getDnpay1()) + tfdoub)
									+ "");
						}
						jud++;
					}
					// yf
					if (!paidFunds[i].equals(dsObject.getPaidFund())) {
						// System.out.println("yf:"+paidFunds[i]+"----"+dsObject.getPaidFund());
						tfdoub1 = -(setFils(dsObject.getPaidFund() + "") - setFils(paidFunds[i]));
						// System.out.println("yf结果："+tfdoub1);
						if (tfdoub1 > 0) {
							dsObject.setDnpay2((setFils(dsObject.getDnpay2()) - tfdoub1)
									+ "");
						}
						if (tfdoub1 < 0) {
							dsObject.setDnpay2((setFils(dsObject.getDnpay2()) + tfdoub1)
									+ "");
						}
						jud++;
					}
					// hf
					if (!conterpartFunds[i]
							.equals(dsObject.getConterpartFund())) {
						tfdoub2 = -(setFils(dsObject.getConterpartFund() + "") - setFils(conterpartFunds[i]));
						// System.out.println("yf结果："+tfdoub1);
						if (tfdoub2 > 0) {
							dsObject.setDnpay3((setFils(dsObject.getDnpay3()) - tfdoub2)
									+ "");
						}
						if (tfdoub2 < 0) {
							dsObject.setDnpay3((setFils(dsObject.getDnpay3()) + tfdoub2)
									+ "");
						}
						jud++;
					}
					// 修改当也总和
					double alls = 0.0;
					if (jud > 0) {
						alls = tfdoub + tfdoub1 + tfdoub2;
						double originalV = setFils(dsObject.getDnpayAll());
						dsObject.setDnpayAll((originalV + alls) + "");
					}
					dsObject.setAgancyFund(setFils(agancyFunds[i]));
					dsObject.setSubmitFund(setFils(submitFunds[i]));
					dsObject.setPaidFund(setFils(paidFunds[i]));
					dsObject.setConterpartFund(setFils(conterpartFunds[i]));
					dsObject.setAnotherPerson(setFiles(anotherPersons[i]));

					// 修改总和数据
					// System.out.println("进入的编码："+dishfRecods[i]);
					List<Dispatch> aloList = this.getDispatchService()
							.getNumToDispatch(dishfRecods[i]);

					List<Dispatch> alkList = this.getDispatchService()
							.getNumpageToDispatch(dishfRecods[i],
									setDsPage(aloList.size()) + "");
					// System.out.println("全部的的大小值："+aloList.size());
					// System.out.println("最后一页大小："+alkList.size());
					if (alkList.size() > 0) {
						for (Dispatch jk : alkList) {
							// System.out.println("(setFils(jk.getAllPay1())+tfdoub):"+jk.getAllPay1()+"-----"+tfdoub);
							// System.out.println("(setFils(jk.getAllPay2())+tfdoub1):"+jk.getAllPay2()+"-----"+tfdoub1);
							// System.out.println("(setFils(jk.getAllPay3())+tfdoub2):"+jk.getAllPay3()+"-----"+tfdoub2);
							// System.out.println("jk.id:"+jk.getId());
							jk.setAllPay1((setFils(jk.getAllPay1()) + tfdoub)
									+ "");
							jk.setAllPay2((setFils(jk.getAllPay2()) + tfdoub1)
									+ "");
							jk.setAllPay3((setFils(jk.getAllPay3()) + tfdoub2)
									+ "");
							jk.setAlltotalPay((setFils(jk.getAlltotalPay()) + alls)
									+ "");
							this.getDispatchService().submit(jk);

						}

					}
					this.getDispatchService().submit(dsObject);
					List<DispatchPerson> dtt = this.getDispatchPersonService().getSizePerson(dsObject.getReceivePerson(),dsObject.getTransportAddress());
					List<Dispatch> pList=this.getDispatchService().getByNameandByAdress(dsObject.getReceivePerson(),dsObject.getTransportAddress());
					if(pList.size()<=0){
						for(DispatchPerson  gh:dtt){
							this.getDispatchPersonService().remove(gh)	;
						}
					
					}
					// 统计数据变更-----------------------------------------------
					setCount(dishfRecods[i]);
					// 修改最后一页数据值,因为是修改当列数据故不用修改最后一页数据

				}

			}
		}
		// 当前页小于24条数据的-----------------------------------------------------
		else if (timeSize < 24) {
			adddisCodes = "";
			// System.out.println("小于24");
			// 删除最后一页的数据
			for (int i = 0; i < timeSize; i++) {
				adddisCodes = dishfRecods[i];
				transportAddress = addAdreess[i];
				// 执行删除操作
				if (setTF(transportCodes[i]) && setTF(receivePersons[i])
						&& setTF(telepones[i]) && setTF(productNames[i])
						&& setTF(productNums[i]) && setTF(agancyFunds[i])
						&& setTF(submitFunds[i]) && setTF(paidFunds[i])
						&& setTF(conterpartFunds[i])
						&& setTF(anotherPersons[i])) {
					// System.out.println("删除数据");
					// 数据删除----------------
					double tfOriginalV = 0.0;
					double hfOriginalV = 0.0;
					double yfOriginalV = 0.0;
					Dispatch dsOnject = this.getDispatchService().get(
							Integer.parseInt(ids[i]));
					tfOriginalV = dsOnject.getSubmitFund();
					hfOriginalV = dsOnject.getPaidFund();
					yfOriginalV = dsOnject.getConterpartFund();
					// 判断该列账簿里面是否有数据
					if (setTF(agancyFunds_ys[i]) == false) {
						// 有数据
						DispatchBook dsBookObject = this
								.getDispatchBookService().getDispatchBook(
										dsOnject);
						if (dsBookObject == null) {
						} else {
							this.getDispatchBookService().remove(dsBookObject);
						}
					}

					// 人员替补操作
					// System.out.println("人员替补：" + pPeronss[i]);
					List<Dispatch> dpList = this.getDispatchService()
							.getByNameandByAdress(pPeronss[i],
									dsOnject.getTransportAddress());
					if (dpList.size() == 0) {
						DispatchPerson pNum = this.getDispatchPersonService()
								.getDispatchPerson(pPeronss[i],
										dsOnject.getTransportAddress());
						if (pNum == null) {
						} else {
							this.getDispatchPersonService().remove(pNum);
						}
					}

					// 删除数据库里面的数据
					this.getDispatchService().remove(dsOnject);
					// 删除后最后一页的数据变更
					List<Dispatch> dsList = this.getDispatchService()
							.getNumpageToDispatch(dishfRecods[i], pagecord);
					for (Dispatch kObject : dsList) {
						// 当页数据设置
						kObject.setDnpay1((setFils(kObject.getDnpay1()) - tfOriginalV)
								+ "");
						kObject.setDnpay2((setFils(kObject.getDnpay2()) - hfOriginalV)
								+ "");
						kObject.setDnpay3((setFils(kObject.getDnpay3()) - yfOriginalV)
								+ "");
						kObject.setDnpayAll((setFils(kObject.getDnpayAll())
								- tfOriginalV - hfOriginalV - yfOriginalV)
								+ "");
						// 统计数据设置
						kObject.setAllPay1((setFils(kObject.getAllPay1()) - tfOriginalV)
								+ "");
						kObject.setAllPay2((setFils(kObject.getAllPay2()) - hfOriginalV)
								+ "");
						kObject.setAllPay3((setFils(kObject.getAllPay3()) - yfOriginalV)
								+ "");
						kObject.setAlltotalPay((setFils(kObject
								.getAlltotalPay()) - tfOriginalV - hfOriginalV - yfOriginalV)
								+ "");
						this.getDispatchService().submit(kObject);
					}
					// 统计数据变更-----------------------------------------------
					setCount(dishfRecods[i]);
				} else {
					// System.out.println("修改数据");
					// 执行修改操作
					Dispatch dsOnject = this.getDispatchService().get(
							Integer.parseInt(ids[i]));
					dsOnject.setTransportCode(setFiles(transportCodes[i]));
					
					// 人员操作
					if (!(receivePersons[i].trim()).equals(dsOnject.getReceivePerson().trim())) {
						
					    DispatchBook bookO=this.getDispatchBookService().getDispatchBook(dsOnject);
					    if(bookO!=null){
					    	bookO.setBoName(receivePersons[i]);
					    	this.getDispatchBookService().submit(bookO);
					    }
						DispatchPerson dt = this.getDispatchPersonService().getDispatchPerson(receivePersons[i],dsOnject.getTransportAddress());
//						List<DispatchPerson> dtt = this.getDispatchPersonService().getSizePerson(dsOnject.getReceivePerson(),dsOnject.getTransportAddress());
//						List<Dispatch> pList=this.getDispatchService().getByNameandByAdress(dsOnject.getReceivePerson(),dsOnject.getTransportAddress());
//						if(pList.size()<=0){
//							for(DispatchPerson  gh:dtt){
//								this.getDispatchPersonService().remove(gh)	;
//							}
//						
//						}
						
						if (dt == null) {
							DispatchPerson dpp = new DispatchPerson();
							dpp.setPeAdress(dsOnject.getTransportAddress());
							dpp.setPeName(receivePersons[i]);
							if ("".equals(telepones[i]) || telepones[i] == null) {
								dpp.setPeTelepone("");
							} else {
								dpp.setPeTelepone(telepones[i]);
							}
							dpp.setPerhfRecod(dsOnject.getDishfRecod());
							this.getDispatchPersonService().save(dpp);

						}

						// 原有人员操作
						// Dispatch
						// dsp=this.getDispatchService().getByNameandByAdress(dsObject.get,
						// adress)
					}
					dsOnject.setReceivePerson(setFiles(receivePersons[i]));
					dsOnject.setTelepone(setFiles(telepones[i]));
					dsOnject.setProductName(productNames[i]);
					dsOnject.setProductNum(Integer.parseInt(productNums[i]));

					// 账簿变更
					if (setFils(agancyFunds[i].trim())!=dsOnject.getAgancyFund()) {
						
						if ("".equals(agancyFunds[i]) || agancyFunds[i] == null) {
							DispatchBook dpBObject = this
									.getDispatchBookService().getDispatchBook(
											this.getDispatchService().get(
													Integer.parseInt(ids[i])));
							if (dpBObject != null) {
								this.getDispatchBookService().remove(dpBObject);
							}
						} else {
							DispatchBook dpBObject = this
									.getDispatchBookService().getDispatchBook(
											this.getDispatchService().get(
													Integer.parseInt(ids[i])));
							if (dpBObject != null) {
								dpBObject.setBoName(receivePersons[i]);
								dpBObject.setBoAmount(setFils(agancyFunds[i]));
								this.getDispatchBookService().submit(dpBObject);
							} else {
								DispatchBook ajObject = new DispatchBook();
								ajObject.setBoAdress(dsOnject
										.getTransportAddress());
								ajObject.setBoAmount(setFils(agancyFunds[i]));
								ajObject.setBoName(receivePersons[i]);
								ajObject.setBoohfRecod(dishfRecods[i]);
								ajObject.setBoDate(new Date());
								ajObject.setBopageNum(pagecord);
								ajObject.setDispatch(dsOnject);
								ajObject.setBoCode(setFiles(transportCodes[i]));
								ajObject.setBoCDate("");
								ajObject.setBoQDate("");
								ajObject.setBoAcName("");
								this.getDispatchBookService()
										.save(ajObject);
							}
						}
//						1
//						if (dsOnject.getAgancyFund()==0
//								|| dsOnject.getAgancyFund() == null) {
//							DispatchBook ajObject = new DispatchBook();
//							ajObject.setBoAdress(dsOnject
//									.getTransportAddress());
//							ajObject.setBoAmount(setFils(agancyFunds[i]));
//							ajObject.setBoName(receivePersons[i]);
//							ajObject.setBoohfRecod(dishfRecods[i]);
//							ajObject.setBoDate(new Date());
//							ajObject.setBopageNum(pagecord);
//							ajObject.setDispatch(dsOnject);
//							ajObject.setBoCode(setFiles(transportCodes[i]));
//							ajObject.setBoCDate("");
//							ajObject.setBoQDate("");
//							ajObject.setBoAcName("");
//							this.getDispatchBookService()
//									.save(ajObject);
//						}
					}

					//
					// if (setFils(agancyFunds[i]) != dsOnject.getAgancyFund())
					// {
					// DispatchBook dbObject =
					// this.getDispatchBookService().getDispatchBook(dsOnject);
					// if (setFils(agancyFunds[i]) == 0) {
					// if (dbObject != null) {
					// this.getDispatchBookService().remove(dbObject);
					// }
					// } else {
					//
					// if (dbObject != null) {
					// dbObject.setBoAmount(setFils(agancyFunds[i]));
					// dbObject.setBoName(setFiles(receivePersons[i]));
					// this.getDispatchBookService().submit(dbObject);
					// }
					// }
					// }

					// 是否更改总值的判断值
					int jud = 0;
					double tfdoub = 0.0;
					double tfdoub1 = 0.0;
					double tfdoub2 = 0.0;

					// tf
					if (!submitFunds[i].equals(dsOnject.getSubmitFund())) {
						tfdoub = -(setFils(dsOnject.getSubmitFund() + "") - setFils(submitFunds[i]));
						if (tfdoub > 0) {
							dsOnject.setDnpay1((setFils(dsOnject.getDnpay1()) - tfdoub)
									+ "");
						}
						if (tfdoub < 0) {
							dsOnject.setDnpay1((setFils(dsOnject.getDnpay1()) + tfdoub)
									+ "");
						}
						jud++;
					}
					// yf
					if (!paidFunds[i].equals(dsOnject.getPaidFund())) {
						tfdoub1 = -(setFils(dsOnject.getPaidFund() + "") - setFils(paidFunds[i]));
						if (tfdoub1 > 0) {
							dsOnject.setDnpay2((setFils(dsOnject.getDnpay2()) - tfdoub1)
									+ "");
						}
						if (tfdoub1 < 0) {
							dsOnject.setDnpay2((setFils(dsOnject.getDnpay2()) + tfdoub1)
									+ "");
						}
						jud++;
					}
					// hf
					if (!conterpartFunds[i]
							.equals(dsOnject.getConterpartFund())) {
						tfdoub2 = -(setFils(dsOnject.getConterpartFund() + "") - setFils(conterpartFunds[i]));
						if (tfdoub2 > 0) {
							dsOnject.setDnpay3((setFils(dsOnject.getDnpay3()) - tfdoub2)
									+ "");
						}
						if (tfdoub2 < 0) {
							dsOnject.setDnpay3((setFils(dsOnject.getDnpay3()) + tfdoub2)
									+ "");
						}
						jud++;
					}
					double alls = 0.0;
					if (jud > 0) {
						// 修改当页总和
						alls = tfdoub + tfdoub1 + tfdoub2;
						double originalV = setFils(dsOnject.getDnpayAll());
						// dsOnject.setDnpayAll((originalV + alls) + "");
						// // 修改统计总和
						// dsOnject.setAllPay1((setFils(dsOnject.getAllPay1()) +
						// tfdoub)
						// + "");
						// dsOnject.setAllPay2((setFils(dsOnject.getAllPay2()) +
						// tfdoub1)
						// + "");
						// dsOnject.setAllPay3((setFils(dsOnject.getAllPay3()) +
						// tfdoub2)
						// + "");
						// dsOnject.setAlltotalPay((setFils(dsOnject
						// .getAlltotalPay()) + alls) + "");

					}
					dsOnject.setAgancyFund(setFils(agancyFunds[i]));
					dsOnject.setSubmitFund(setFils(submitFunds[i]));
					dsOnject.setPaidFund(setFils(paidFunds[i]));
					dsOnject.setConterpartFund(setFils(conterpartFunds[i]));
					dsOnject.setAnotherPerson(setFiles(anotherPersons[i]));

					List<Dispatch> alkList = this.getDispatchService()
							.getNumpageToDispatch(dishfRecods[i], pagecord);
					// System.out.println("全部的的大小值："+aloList.size());
					// System.out.println("最后一页大小："+alkList.size());
					if (alkList.size() > 0) {
						for (Dispatch jk : alkList) {
							// System.out.println("(setFils(jk.getAllPay1())+tfdoub):"+jk.getAllPay1()+"-----"+tfdoub);
							// System.out.println("(setFils(jk.getAllPay2())+tfdoub1):"+jk.getAllPay2()+"-----"+tfdoub1);
							// System.out.println("(setFils(jk.getAllPay3())+tfdoub2):"+jk.getAllPay3()+"-----"+tfdoub2);
							// System.out.println("jk.id:"+jk.getId());
							jk.setAllPay1((setFils(jk.getAllPay1()) + tfdoub)
									+ "");
							jk.setAllPay2((setFils(jk.getAllPay2()) + tfdoub1)
									+ "");
							jk.setAllPay3((setFils(jk.getAllPay3()) + tfdoub2)
									+ "");
							jk.setAlltotalPay((setFils(jk.getAlltotalPay()) + alls)
									+ "");
							this.getDispatchService().submit(jk);

						}

					}

					this.getDispatchService().submit(dsOnject);
					List<DispatchPerson> dtt = this.getDispatchPersonService().getSizePerson(dsOnject.getReceivePerson(),dsOnject.getTransportAddress());
					List<Dispatch> pList=this.getDispatchService().getByNameandByAdress(dsOnject.getReceivePerson(),dsOnject.getTransportAddress());
					if(pList.size()<=0){
						for(DispatchPerson  gh:dtt){
							this.getDispatchPersonService().remove(gh)	;
						}
					
					}
					// 统计数据变更-----------------------------------------------
					setCount(dishfRecods[i]);
				}
			}
			// 小于24条数据的时候还存在，用户新增数据
			// 最后一页新加的数据
			int addSize = addreceivePersons.length;
			if (addSize > 0) {
				for (int j = 0; j < addSize; j++) {
					if ("".equals(addreceivePersons[j])
							|| addreceivePersons[j] == null) {

					} else {

						Dispatch addObject = new Dispatch();
						addObject.setTransportAddress(transportAddress);
						addObject.setDishfRecod(adddisCodes);
						addObject.setDispageNum(pagecord);
						addObject
								.setTransportCode(setFiles(addtransportCodes[j]));
						addObject
								.setReceivePerson(setFiles(addreceivePersons[j]));
						// 人员操作
						// // System.out.println("addreceivePersons[j]:"
						// + addreceivePersons[j]);
						// System.out.println("transportAddress:"
						// + transportAddress);
						DispatchPerson dt = this.getDispatchPersonService()
								.getDispatchPerson(addreceivePersons[j],
										transportAddress);
						if (dt == null) {
							DispatchPerson dpp = new DispatchPerson();
							dpp.setPeAdress(transportAddress);
							dpp.setPeName(addreceivePersons[j]);
							if ("".equals(addtelepones[j])
									|| addtelepones[j] == null) {
								dpp.setPeTelepone("");
							} else {
								dpp.setPeTelepone(addtelepones[j]);
							}
							dpp.setPerhfRecod(adddisCodes);
							this.getDispatchPersonService().save(dpp);
						}
						addObject.setTelepone(setFiles(addtelepones[j]));
						addObject.setProductName(setFiles(addproductNames[j]));
						addObject.setProductNum(Integer
								.parseInt(addproductNums[j]));
						// 新增代收款操作
						addObject.setAgancyFund(setFils(addagancyFunds[j]));
						
						addObject.setSubmitFund(setFils(addsubmitFunds[j]));
						addObject.setPaidFund(setFils(addpaidFunds[j]));
						addObject
								.setConterpartFund(setFils(addconterpartFunds[j]));
						addObject
								.setAnotherPerson(setFiles(addanotherPersons[j]));
						// 当页数据操作,数据操作
						addObject.setDnpay1(setFils(addsubmitFunds[j]) + "");
						addObject.setDnpay2(setFils(addpaidFunds[j]) + "");
						addObject
								.setDnpay3(setFils(addconterpartFunds[j]) + "");
						addObject
								.setDnpayAll((setFils(addsubmitFunds[j])
										+ setFils(addpaidFunds[j]) + setFils(addconterpartFunds[j]))
										+ "");
						// 操作统计的数据

						addObject.setAllPay1(setFils(allpay1) + "");
						addObject.setAllPay2(setFils(allpay2) + "");
						addObject.setAllPay3(setFils(allpay3) + "");
						addObject.setAlltotalPay(setFils(allpayAlls) + "");

						addObject.setTransportDate(new Date());
						this.getDispatchService().save(addObject);
						// 账簿中新加入

					
						if (setFils(addagancyFunds[j]) > 0) {
							DispatchBook dbObject = new DispatchBook();
							dbObject.setBoAdress(transportAddress);
							dbObject.setBoAmount(setFils(addagancyFunds[j]));
							dbObject.setBoName(addreceivePersons[j]);
							dbObject.setBoohfRecod(adddisCodes);
							dbObject.setBopageNum(pagecord);					
							dbObject.setBoDate(new Date());
							dbObject.setBoCode(setFiles(addtransportCodes[j]));
							dbObject.setBoCDate("");
							dbObject.setBoQDate("");
							dbObject.setBoAcName("");										
							dbObject.setDispatch(addObject);
							this.getDispatchBookService().save(dbObject);
						}
						// 统计数据变更-----------------------------------------------
						setCount(dishfRecods[(timeSize-1)]);
						// 数据变更

						List<Dispatch> dList = this.getDispatchService()
								.getNumpageToDispatch(adddisCodes, pagecord);
						if (dList.size() > 0) {
							// 统计综合计算
							List<Dispatch> dListjh = this.getDispatchService()
									.getNumToDispatch(adddisCodes);
							double paysk1 = 0.0;
							double paysk2 = 0.0;
							double paysk3 = 0.0;
							double payskAll = 0.0;
							if (dListjh.size() > 0) {
								for (Dispatch kl : dListjh) {
									paysk1 = paysk1 + kl.getSubmitFund();
									paysk2 = paysk2 + kl.getPaidFund();
									paysk3 = paysk3 + kl.getConterpartFund();
								}
								payskAll = paysk1 + paysk2 + paysk3;
							}
							// 统计当页数据
							double paysm1 = 0.0;
							double paysm2 = 0.0;
							double paysm3 = 0.0;
							double paysmAll = 0.0;
							for (Dispatch mm : dList) {
								paysm1 = paysm1 + mm.getSubmitFund();
								paysm2 = paysm2 + mm.getPaidFund();
								paysm3 = paysm3 + mm.getConterpartFund();

							}
							paysmAll = paysm3 + paysm2 + paysm1;

							for (Dispatch df : dList) {

								df.setDnpay1(paysm1 + "");
								df.setDnpay2(paysm2 + "");
								df.setDnpay3(paysm3 + "");
								df.setDnpayAll(paysmAll + "");

								df.setAllPay1(paysk1 + "");
								df.setAllPay2(paysk2 + "");
								df.setAllPay3(paysk3 + "");
								df.setAlltotalPay(payskAll + "");
								this.getDispatchService().submit(df);
							}
							// 统计数据变更-----------------------------------------------
							setCount(dishfRecods[(timeSize-1)]);
						}

					}

				}
			}
			// over
		}
		this.setPrompt("数据处理中........");
		return SUCCESS;
	}

	public Double updaData(String a, String b) {
		double tfV = 0.0;
		if (!a.equals(b)) {
			if ("".equals(a.trim()) || a.trim() == null || "0".equals(a.trim())
					|| "0.0".equals(a.trim())) {
				a = "0";
			}
			if ("".equals(b.trim()) || b.trim() == null || "0".equals(a.trim())
					|| "0.0".equals(a.trim())) {
				b = "0";
			}
			double starta = Double.parseDouble(a);
			double endb = Double.parseDouble(b);
			// 现在数据- 原始数据
			tfV = endb - starta;
		}
		return tfV;
	}

	/**
	 * 单据最后一页的数据
	 * 
	 * @param num
	 * @return
	 */
	public List<Dispatch> serchDispatch(String num) {
		List<Dispatch> aLLlist = null;
		List<Dispatch> alist = this.getDispatchService().getNumToDispatch(num);
		int sLength = alist.size();
		if (sLength > 24) {
			int pageNv = 0;
			int yu = sLength % 24;
			if (yu == 0) {
				pageNv = sLength / 24;
			} else {
				pageNv = sLength / 24 + 1;
			}
			aLLlist = this.getDispatchService().getNumpageToDispatch(num,
					pageNv + "");
		} else {
			aLLlist = alist;
		}

		return aLLlist;
	}

	public String NewTime() {
		int yyyy, MM, dd;
		Calendar c = Calendar.getInstance();
		yyyy = c.get(Calendar.YEAR);
		MM = c.get(Calendar.MONTH) + 1;
		dd = c.get(Calendar.DAY_OF_MONTH);
		String Times = yyyy + "年" + MM + "月" + dd + "日";
		return Times;
	}

	public Date getDateTime() {

		return new Date();
	}

	public PaginationSupport getPagination() {
		return pagination;
	}

	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}

	public String[] getIds() {
		return ids;
	}

	public void setIds(String[] ids) {
		this.ids = ids;
	}

	public String[] getIds2() {
		return ids2;
	}

	public void setIds2(String[] ids2) {
		this.ids2 = ids2;
	}

	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public String getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public Dispatch getDispatch() {
		return dispatch;
	}

	public void setDispatch(Dispatch dispatch) {
		this.dispatch = dispatch;
	}

	public String getTransportAddress() {
		return transportAddress;
	}

	public void setTransportAddress(String transportAddress) {
		this.transportAddress = transportAddress;
	}

	public String getHidDtime() {
		return hidDtime;
	}

	public void setHidDtime(String hidDtime) {
		this.hidDtime = hidDtime;
	}

	public Date getDtime() {
		return Dtime;
	}

	public void setDtime(Date dtime) {
		Dtime = dtime;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public DispatchService getDispatchService() {
		return dispatchService;
	}

	public void setDispatchService(DispatchService dispatchService) {
		this.dispatchService = dispatchService;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	public String getMaPay() {
		return MaPay;
	}

	public void setMaPay(String maPay) {
		MaPay = maPay;
	}

	public String[] getReceiver() {
		return receiver;
	}

	public void setReceiver(String[] receiver) {
		this.receiver = receiver;
	}

	public String[] getCodeNumber() {
		return codeNumber;
	}

	public void setCodeNumber(String[] codeNumber) {
		this.codeNumber = codeNumber;
	}

	public String[] getPhone() {
		return phone;
	}

	public void setPhone(String[] phone) {
		this.phone = phone;
	}

	public String[] getProductName() {
		return productName;
	}

	public void setProductName(String[] productName) {
		this.productName = productName;
	}

	public Double[] getCollection() {
		return collection;
	}

	public void setCollection(Double[] collection) {
		this.collection = collection;
	}

	public String[] getNumbers() {
		return Numbers;
	}

	public void setNumbers(String[] numbers) {
		Numbers = numbers;
	}

	public Double[] getPay1() {
		return pay1;
	}

	public void setPay1(Double[] pay1) {
		this.pay1 = pay1;
	}

	public Double[] getPay2() {
		return pay2;
	}

	public void setPay2(Double[] pay2) {
		this.pay2 = pay2;
	}

	public Double[] getPay3() {
		return pay3;
	}

	public void setPay3(Double[] pay3) {
		this.pay3 = pay3;
	}

	public String[] getReceiveName() {
		return receiveName;
	}

	public void setReceiveName(String[] receiveName) {
		this.receiveName = receiveName;
	}

	public DispatchPerson getDispatchPerson() {
		return dispatchPerson;
	}

	public void setDispatchPerson(DispatchPerson dispatchPerson) {
		this.dispatchPerson = dispatchPerson;
	}

	public DispatchPersonService getDispatchPersonService() {
		return dispatchPersonService;
	}

	public void setDispatchPersonService(
			DispatchPersonService dispatchPersonService) {
		this.dispatchPersonService = dispatchPersonService;
	}

	public DispatchBook getDispatchBook() {
		return dispatchBook;
	}

	public void setDispatchBook(DispatchBook dispatchBook) {
		this.dispatchBook = dispatchBook;
	}

	public DispatchBookService getDispatchBookService() {
		return dispatchBookService;
	}

	public void setDispatchBookService(DispatchBookService dispatchBookService) {
		this.dispatchBookService = dispatchBookService;
	}

	public String getDtime1() {
		return Dtime1;
	}

	public void setDtime1(String dtime1) {
		Dtime1 = dtime1;
	}

	@SuppressWarnings("rawtypes")
	public List getNumList() {
		return numList;
	}

	@SuppressWarnings("rawtypes")
	public void setNumList(List numList) {
		this.numList = numList;
	}

	public int[] getNums() {
		return nums;
	}

	public void setNums(int[] nums) {
		this.nums = nums;
	}

	public String getJudge() {
		return judge;
	}

	public void setJudge(String judge) {
		this.judge = judge;
	}

	public String getPagecord() {
		return pagecord;
	}

	public void setPagecord(String pagecord) {
		this.pagecord = pagecord;
	}

	public String getJudgepage() {
		return judgepage;
	}

	public void setJudgepage(String judgepage) {
		this.judgepage = judgepage;
	}

	public Recodhaifen getRecodhaifen() {
		return recodhaifen;
	}

	public void setRecodhaifen(Recodhaifen recodhaifen) {
		this.recodhaifen = recodhaifen;
	}

	public RecodhaifenService getRecodhaifenService() {
		return recodhaifenService;
	}

	public void setRecodhaifenService(RecodhaifenService recodhaifenService) {
		this.recodhaifenService = recodhaifenService;
	}

	public String getTotal_pay1() {
		return total_pay1;
	}

	public void setTotal_pay1(String total_pay1) {
		this.total_pay1 = total_pay1;
	}

	public String getTotal_pay2() {
		return total_pay2;
	}

	public void setTotal_pay2(String total_pay2) {
		this.total_pay2 = total_pay2;
	}

	public String getTotal_pay3() {
		return total_pay3;
	}

	public void setTotal_pay3(String total_pay3) {
		this.total_pay3 = total_pay3;
	}

	public String getTotal() {
		return total;
	}

	public void setTotal(String total) {
		this.total = total;
	}

	/**
	 * xin匹配
	 * 
	 * @return
	 */
	public String getRedNew() {
		int yyyy, MM, dd;
		Calendar c = Calendar.getInstance();
		yyyy = c.get(Calendar.YEAR);
		MM = c.get(Calendar.MONTH) + 1;
		dd = c.get(Calendar.DAY_OF_MONTH);
		String Times = yyyy + "" + MM + "" + dd + "";
		String allR = (Times + "H" + 0).trim();
		Recodhaifen hfg = new Recodhaifen();
		hfg.setRecordNum(allR);
		this.getRecodhaifenService().save(hfg);
		return allR;

	}

	/**
	 * 递增操作
	 */
	public void AddRe(Recodhaifen hf) {
		String oldV = hf.getRecordNum();
		String f_v[] = oldV.split("H");
		String va_bb = (Integer.parseInt(f_v[1]) + 1) + "";
		String vv = f_v[0] + "H" + va_bb;
		this.getRecodhaifenService().updateRecord(vv, hf);
	}

	public void CandleNull() {
		if (total_pay1 == null) {
			total_pay1 = "";
		}
		if (total_pay2 == null) {
			total_pay2 = "";
		}
		if (total_pay3 == null) {
			total_pay3 = "";
		}
		if (total == null) {
			total = "";
		}
	}

	public void FilterNull2(int i) {
		if (transportCodes[i] == null || "".equals(transportCodes[i].trim())) {
			transportCodes[i] = "";
		}
		if (telepones[i] == null || "".equals(telepones[i].trim())) {
			telepones[i] = "";
		}
		if (receivePersons[i] == null || "".equals(receivePersons[i].trim())) {
			receivePersons[i] = "";
		}
		if (productNames[i] == null || "".equals(productNames[i].trim())) {
			productNames[i] = "";
		}
		if (productNums[i] == null || "".equals(productNums[i].trim())) {
			productNums[i] = "";
		}
		if (paidFunds[i] == null || "".equals(paidFunds[i].trim())) {
			paidFunds[i] = "";
		}
		if (submitFunds[i] == null || "".equals(submitFunds[i].trim())) {
			submitFunds[i] = "";
		}
		if (conterpartFunds[i] == null || "".equals(conterpartFunds[i].trim())) {
			conterpartFunds[i] = "";
		}
		if (anotherPersons[i] == null || "".equals(anotherPersons[i].trim())) {
			anotherPersons[i] = "";
		}

	}

	public void FilterNull(int i) {

		if (codeNumber[i] == null || "".equals(codeNumber[i])) {
			codeNumber[i] = "";
		}

		if (phone[i] == null || "".equals(phone[i])) {
			phone[i] = "";
		}

		if (productName[i] == null || "".equals(productName[i])) {
			productName[i] = "";
		}

		if (collection[i] == null || "".equals(collection[i])
				|| collection[i] == 0) {
			collection[i] = 0.0;
		}

		if (receiveName[i] == null || "".equals(receiveName[i])) {
			receiveName[i] = "";
		}
		if (pay1[i] == null || "".equals(pay1[i]) || pay1[i] == 0) {
			pay1[i] = 0.0;
		}

		if (pay2[i] == null || "".equals(pay2[i]) || pay2[i] == 0) {
			pay2[i] = 0.0;

		}

		if (pay3[i] == null || "".equals(pay3[i]) || pay3[i] == 0) {
			pay3[i] = 0.0;
		}
	}

	/**
	 * 提付金额
	 * 
	 * @return
	 */
	public Double SysoutPay1(int ragular) {
		double v_pay1 = 0.0;
		if (MaPay == null || "".equals(MaPay)) {
			for (int i = 0; i < ragular; i++) {
				if (pay1[i] != null) {
					v_pay1 = v_pay1 + pay1[i];
				}
			}
		} else {
			String mapays[] = (MaPay.trim()).split(",");
			double fv = Double.parseDouble(mapays[0]);
			for (int i = 0; i < ragular; i++) {
				if (pay1[i] != null) {
					v_pay1 = v_pay1 + pay1[i];
				}
			}
			v_pay1 = v_pay1 + fv;
		}

		return v_pay1;
	}

	/**
	 * 已付金额
	 * 
	 * @return
	 */
	public Double SysoutPay2(int ragular) {
		double v_pay1 = 0.0;
		if (MaPay == null || "".equals(MaPay.trim())) {
			for (int i = 0; i < ragular; i++) {
				if (pay2[i] != null) {
					v_pay1 = v_pay1 + pay2[i];
				}
			}
		} else {
			String mapays[] = (MaPay.trim()).split(",");
			double fv = Double.parseDouble(mapays[1]);
			for (int i = 0; i < ragular; i++) {
				if (pay2[i] != null) {
					v_pay1 = v_pay1 + pay2[i];
				}
			}
			v_pay1 = v_pay1 + fv;
		}

		return v_pay1;
	}

	/**
	 * 回付金额
	 * 
	 * @return
	 */
	public Double SysoutPay3(int ragular) {
		double v_pay1 = 0.0;
		if (MaPay == null || "".equals(MaPay.trim())) {
			for (int i = 0; i < ragular; i++) {
				if (pay3[i] != null) {
					v_pay1 = v_pay1 + pay3[i];
				}
			}
		} else {
			String mapays[] = (MaPay.trim()).split(",");
			double fv = Double.parseDouble(mapays[2]);
			for (int i = 0; i < ragular; i++) {
				if (pay3[i] == null) {

				} else {
					v_pay1 = v_pay1 + pay3[i];
				}
			}
			v_pay1 = v_pay1 + fv;
		}
		return v_pay1;
	}

	public String getCitys() {
		return citys;
	}

	public void setCitys(String citys) {
		this.citys = citys;
	}

	public String getNextadressid() {
		return nextadressid;
	}

	public void setNextadressid(String nextadressid) {
		this.nextadressid = nextadressid;
	}

	public String getSerA() {
		return SerA;
	}

	public void setSerA(String serA) {
		SerA = serA;
	}

	public String[] getTransportCodes() {
		return transportCodes;
	}

	public void setTransportCodes(String[] transportCodes) {
		this.transportCodes = transportCodes;
	}

	public String[] getReceivePersons() {
		return receivePersons;
	}

	public void setReceivePersons(String[] receivePersons) {
		this.receivePersons = receivePersons;
	}

	public String[] getTelepones() {
		return telepones;
	}

	public void setTelepones(String[] telepones) {
		this.telepones = telepones;
	}

	public String[] getProductNames() {
		return productNames;
	}

	public void setProductNames(String[] productNames) {
		this.productNames = productNames;
	}

	public String[] getProductNums() {
		return productNums;
	}

	public void setProductNums(String[] productNums) {
		this.productNums = productNums;
	}

	public String[] getAgancyFunds() {
		return agancyFunds;
	}

	public void setAgancyFunds(String[] agancyFunds) {
		this.agancyFunds = agancyFunds;
	}

	// public Double[] getSubmitFunds() {
	// return submitFunds;
	// }
	//
	// public void setSubmitFunds(Double[] submitFunds) {
	// this.submitFunds = submitFunds;
	// }

	public String[] getSubmitFunds() {
		return submitFunds;
	}

	public String[] getPaidFunds() {
		return paidFunds;
	}

	public void setSubmitFunds(String[] submitFunds) {
		this.submitFunds = submitFunds;
	}

	public String[] getConterpartFunds() {
		return conterpartFunds;
	}

	public void setConterpartFunds(String[] conterpartFunds) {
		this.conterpartFunds = conterpartFunds;
	}

	public void setPaidFunds(String[] paidFunds) {
		this.paidFunds = paidFunds;
	}

	String[] getAnotherPersons() {
		return anotherPersons;
	}

	public void setAnotherPersons(String[] anotherPersons) {
		this.anotherPersons = anotherPersons;
	}

	public String[] getDishfRecods() {
		return dishfRecods;
	}

	public void setDishfRecods(String[] dishfRecods) {
		this.dishfRecods = dishfRecods;
	}

	public String[] getAgancyFunds_ys() {
		return agancyFunds_ys;
	}

	public void setAgancyFunds_ys(String[] agancyFunds_ys) {
		this.agancyFunds_ys = agancyFunds_ys;
	}

	public String getPay1x() {
		return pay1x;
	}

	public void setPay1x(String pay1x) {
		this.pay1x = pay1x;
	}

	public String getPay2x() {
		return pay2x;
	}

	public void setPay2x(String pay2x) {
		this.pay2x = pay2x;
	}

	public String getPay3x() {
		return pay3x;
	}

	public void setPay3x(String pay3x) {
		this.pay3x = pay3x;
	}

	public String getAllpay() {
		return allpay;
	}

	public void setAllpay(String allpay) {
		this.allpay = allpay;
	}

	public String getPay1_ys() {
		return pay1_ys;
	}

	public void setPay1_ys(String pay1_ys) {
		this.pay1_ys = pay1_ys;
	}

	public String getPay2_ys() {
		return pay2_ys;
	}

	public void setPay2_ys(String pay2_ys) {
		this.pay2_ys = pay2_ys;
	}

	public String getPay3_ys() {
		return pay3_ys;
	}

	public void setPay3_ys(String pay3_ys) {
		this.pay3_ys = pay3_ys;
	}

	public String getAllpay_ys() {
		return allpay_ys;
	}

	public void setAllpay_ys(String allpay_ys) {
		this.allpay_ys = allpay_ys;
	}

	public String getEncode() {
		return Encode;
	}

	public void setEncode(String encode) {
		Encode = encode;
	}

	public CodeInvoice getCodeInvoice() {
		return codeInvoice;
	}

	public void setCodeInvoice(CodeInvoice codeInvoice) {
		this.codeInvoice = codeInvoice;
	}

	public CodeInvoiceService getCodeInvoiceService() {
		return codeInvoiceService;
	}

	public SerCurrentDateService getSerCurrentDateService() {
		return serCurrentDateService;
	}

	public void setSerCurrentDateService(
			SerCurrentDateService serCurrentDateService) {
		this.serCurrentDateService = serCurrentDateService;
	}

	public void setCodeInvoiceService(CodeInvoiceService codeInvoiceService) {
		this.codeInvoiceService = codeInvoiceService;
	}

	public Collection<CodeInvoice> getCodelist() {
		return codelist;
	}

	public void setCodelist(Collection<CodeInvoice> codelist) {
		this.codelist = codelist;
	}

	public Code getCode() {
		return code;
	}

	public void setCode(Code code) {
		this.code = code;
	}

	public CodeService getCodeService() {
		return codeService;
	}

	public void setCodeService(CodeService codeService) {
		this.codeService = codeService;
	}

	public static String Increase(String backupNum) {
		String Inc = "";
		int lengths = backupNum.length();
		String lengthss = (Integer.parseInt(backupNum) + 1) + "";
		int increase = (lengthss.trim()).length();
		if (lengths != increase) {
			String In = "";
			for (int i = 0; i < lengths - increase; i++) {
				In = In + "0";
			}
			In = (In + lengthss).trim();
			Inc = In;
		} else {
			Inc = lengthss;
		}
		return Inc.trim();
	}

	public String getSerB() {
		return SerB;
	}

	public void setSerB(String serB) {
		SerB = serB;
	}

	/**
	 * 判断是否有值
	 * 
	 * @param kk
	 * @return
	 */
	public boolean setTF(String kk) {
		boolean h = false;
		if ("".equals(kk.trim())) {
			h = true;
		}
		if (kk.trim() == null) {
			h = true;
		}
		return h;
	}

	/**
	 * 判断有几页
	 * 
	 * @param num
	 * @return
	 */
	public int setDsPage(int num) {
		int s = 0;
		int yu = num % 24;
		int zu = num / 24;
		if (yu == 0) {
			s = zu;
		} else {
			s = zu + 1;
		}
		return s;
	}

	/**
	 * 单个值过滤
	 * 
	 * @return
	 */
	public double setFils(String num) {

		double s = 0.0;
		if (num.trim() == null || "".equals(num.trim())) {

		} else {
			s = Double.parseDouble(num);
		}
		return s;
	}

	/**
	 * 单个字符串缕空
	 * 
	 * @return
	 */
	public String setFiles(String hg) {
		if ("".equals(hg.trim()) || hg.trim() == null) {
			return "";
		} else {
			return hg;
		}
	}

	public String[] getTtfVpay() {
		return ttfVpay;
	}

	public void setTtfVpay(String[] ttfVpay) {
		this.ttfVpay = ttfVpay;
	}

	public String[] getYyfVpay() {
		return yyfVpay;
	}

	public void setYyfVpay(String[] yyfVpay) {
		this.yyfVpay = yyfVpay;
	}

	public String[] getHhfVpay() {
		return hhfVpay;
	}

	public void setHhfVpay(String[] hhfVpay) {
		this.hhfVpay = hhfVpay;
	}

	public String[] getpPeronss() {
		return pPeronss;
	}

	public void setpPeronss(String[] pPeronss) {
		this.pPeronss = pPeronss;
	}

	public String[] getAddJuds() {
		return addJuds;
	}

	public void setAddJuds(String[] addJuds) {
		this.addJuds = addJuds;
	}

	public String getAdddisCodes() {
		return adddisCodes;
	}

	public void setAdddisCodes(String adddisCodes) {
		this.adddisCodes = adddisCodes;
	}

	public String[] getAddtransportCodes() {
		return addtransportCodes;
	}

	public void setAddtransportCodes(String[] addtransportCodes) {
		this.addtransportCodes = addtransportCodes;
	}

	public String[] getAddreceivePersons() {
		return addreceivePersons;
	}

	public void setAddreceivePersons(String[] addreceivePersons) {
		this.addreceivePersons = addreceivePersons;
	}

	public String[] getAddtelepones() {
		return addtelepones;
	}

	public void setAddtelepones(String[] addtelepones) {
		this.addtelepones = addtelepones;
	}

	public String[] getAddproductNames() {
		return addproductNames;
	}

	public void setAddproductNames(String[] addproductNames) {
		this.addproductNames = addproductNames;
	}

	public String[] getAddproductNums() {
		return addproductNums;
	}

	public void setAddproductNums(String[] addproductNums) {
		this.addproductNums = addproductNums;
	}

	public String[] getAddagancyFunds() {
		return addagancyFunds;
	}

	public void setAddagancyFunds(String[] addagancyFunds) {
		this.addagancyFunds = addagancyFunds;
	}

	public String[] getAddsubmitFunds() {
		return addsubmitFunds;
	}

	public void setAddsubmitFunds(String[] addsubmitFunds) {
		this.addsubmitFunds = addsubmitFunds;
	}

	public String[] getAddpaidFunds() {
		return addpaidFunds;
	}

	public void setAddpaidFunds(String[] addpaidFunds) {
		this.addpaidFunds = addpaidFunds;
	}

	public String[] getAddconterpartFunds() {
		return addconterpartFunds;
	}

	public void setAddconterpartFunds(String[] addconterpartFunds) {
		this.addconterpartFunds = addconterpartFunds;
	}

	public String[] getAddAdreess() {
		return addAdreess;
	}

	public void setAddAdreess(String[] addAdreess) {
		this.addAdreess = addAdreess;
	}

	public String[] getAddanotherPersons() {
		return addanotherPersons;
	}

	public void setAddanotherPersons(String[] addanotherPersons) {
		this.addanotherPersons = addanotherPersons;
	}

	public String getAllpay1() {
		return allpay1;
	}

	public void setAllpay1(String allpay1) {
		this.allpay1 = allpay1;
	}

	public String getAllpay2() {
		return allpay2;
	}

	public void setAllpay2(String allpay2) {
		this.allpay2 = allpay2;
	}

	public String getAllpay3() {
		return allpay3;
	}

	public void setAllpay3(String allpay3) {
		this.allpay3 = allpay3;
	}

	public String getAllpayAlls() {
		return allpayAlls;
	}

	public void setAllpayAlls(String allpayAlls) {
		this.allpayAlls = allpayAlls;
	}

	public String getBillNum() {
		return billNum;
	}

	public void setBillNum(String billNum) {
		this.billNum = billNum;
	}

	/**
	 * 设置所有的数据
	 * 
	 * @param dishfCode
	 */
	public void setCount(String dishfCode) {
		List<Dispatch> lastList = this.getDispatchService().getNumToDispatch(
				dishfCode);
		int seizs = lastList.size();
		// 有数据的操作
		if (seizs > 0) {
			// 数据累加
			double tfData = 0.0;
			double yfData = 0.0;
			double hfData = 0.0;
			for (Dispatch datas : lastList) {
				tfData = tfData + datas.getSubmitFund();
				yfData = yfData + datas.getPaidFund();
				hfData = hfData + datas.getConterpartFund();
			}
			for (Dispatch dataO : lastList) {
				dataO.setAllPay1(tfData + "");
				dataO.setAllPay2(yfData + "");
				dataO.setAllPay3(hfData + "");
				dataO.setAlltotalPay((tfData + yfData + hfData) + "");
				this.getDispatchService().submit(dataO);
			}

		}
	}

	/**
	 * 历史数据统计设置
	 */
	public void countData(){
	
    List<SerCurrentDate>  countList=this.getSerCurrentDateService().getByCurrentTimeData();
   int size=countList.size();
   if(size>0){
	   DateFormat ddf=new SimpleDateFormat("yyyy-MM-dd"); 
	   DateFormat ddf1=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 
	   String endTimes="";
	   Date endH=null;
	   String currentTime="";
	 for(SerCurrentDate currentTimes:countList){
		 currentTime=ddf.format(currentTimes.getDateFund());
		 endTimes=currentTime+" 24:59:60";
		 try {
			endH=ddf1.parse(endTimes);
		} catch (ParseException e) {

			e.printStackTrace();
		}
	List<Dispatch> disList=this.getDispatchService().getByCurrentTimeData(currentTimes.getDateFund(),endH);
	
	int gsize=disList.size();
	double tfV=0.0;//提付
	double yfV=0.0;//已付
	double hfV=0.0;//回付
	if(gsize>0){		
		for(Dispatch dc:disList){
//			System.out.println("A:"+dc.getSubmitFund()+" = "+dc.getPaidFund()+" = "+dc.getConterpartFund());
			tfV=tfV+dc.getSubmitFund();
			yfV=yfV+dc.getPaidFund();
			hfV=hfV+dc.getConterpartFund();
		}
	}
	currentTimes.setSubmitFund(tfV);
	currentTimes.setPaidFund(yfV);
	currentTimes.setConterpartFund(hfV);
	currentTimes.setTotalFund(tfV+yfV+hfV);
	this.getSerCurrentDateService().submit(currentTimes);
	 }
    }
   }

}
